//
//  RecommendationViewModel.swift
//  FeastBooking
//
//  Created by Imon on 2017/10/6.
//  Copyright © 2017年 Imon. All rights reserved.
//

import Foundation
import RxSwift
import Moya

class RecommendationViewModel {
    
    public static let share = RecommendationViewModel()
    
    private var provider: RxMoyaProvider<RecommendationApi>
    
    private init() {
        let endpointClosure = { (target: RecommendationApi) -> Endpoint<RecommendationApi> in
            let defaultEndpoint = RxMoyaProvider.defaultEndpointMapping(for: target)
            return defaultEndpoint.adding(newHTTPHeaderFields: ["content-type": "application/json"])
        }
        provider = RxMoyaProvider<RecommendationApi>(endpointClosure: endpointClosure)
    }
    
    func getRecommendations() -> Observable<[RecommendationResponse]> {
        return provider.request(.getRecommendations())
               .mapJSON()
               .mapArray(type: RecommendationResponse.self)
    }
}
